package encrypt

import (
	"golang.org/x/crypto/bcrypt"
	"log"
)

//加密
func UseBcrypt(password string) string {
	hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.MinCost)
	if err != nil {
		log.Fatal(err)
	}
	return string(hash)
}

//将密码 和 经过加密的密码 比对
func ValidatePasswords(hashedPassword, password []byte) bool {
	byteHash := []byte(hashedPassword)
	err := bcrypt.CompareHashAndPassword(byteHash, password)
	if err != nil {
		return false
	}
	return true
}
